<?php


namespace app\controller;
use app\model\User;
use app\tools\ResponseTool;
use app\validate\user\UserLogin;
use think\exception\ValidateException;
use think\facade\Cache;
use think\facade\Log;
use think\facade\Request;

class PasswordForget
{
    function PasswordForget () {

        $telNum = Request::param('telNum');
        $validateCode = Request::param('validateCode');
        $userPassword = Request::param('userPassword');
        $userInfo = new User();
        $selInfo = $userInfo->where('tel_num', $telNum)->findOrEmpty();
//        Log::record(Request::param());
//        Log::record(Cache::get($telNum));
        if ($selInfo->isEmpty()) {
            return ResponseTool::getRs('PARAM_ERROR',  [], '你的手机号尚未注册');
        } else if ($validateCode && $validateCode == Cache::get($telNum)) {
            $selInfo->user_password = $userPassword;
            if ($selInfo->save()) {
                Log::record(2);
                return ResponseTool::getRs('OK',  [], '密码修改成功');
            } else {
                return ResponseTool::getRs('OTHERS',  [], '服务器忙');
            }
        } else {
            return ResponseTool::getRs('PARAM_ERROR',  [], '短信验证码过期或失效');
        }
    }
}